from rest_framework.permissions import BasePermission


class AccPermission(BasePermission):
    def has_permission(self, request, view):
        if request.method == 'GET' and view.action == 'list':
            return True

        path_parts = request.path.strip('/').split('/')
        required_code = f"acc:{':'.join(path_parts)}"
        return required_code in request.auth.get('perms', [])


class MenuPermission(BasePermission):
    def has_permission(self, request, view):
        return any([
            request.user.is_superuser,
            request.auth.get('is_menu_admin')
        ])
